<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Traits\ApiResponse;

class BaseController extends Controller
{
    use ApiResponse;
    protected $guard = 'api'; //如果不设置成员变量，使用的时候请使用助手函数，例如：$token = auth('api')->tokenById($uid);
    /**
     * Create a new AuthController instance.
     *
     * @return void
     */
    public function __construct()
    {
        // $this->middleware('refresh', ['except' => ['login','register']]);
    }

    /**
     * 获取用户权限，并判断该用户是否有对应权限
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2022-03-31
     * @param [type] $user
     * @return void
     */
    public function getUserPermission($user)
    {
        $curr_api = str_replace('api/', '', request()->path());

        if (in_array($curr_api, collect($user['permission'])->pluck('action')->toArray())) {
            return fail_message('没有操作权限');
        }
    }
}
